package com.example.tetris.ui.ScoreboardScreen

import android.util.Log
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.tetris.drawMatrix
import com.example.tetris.drawSpirit
import com.example.tetris.logic.NextMatrix
import com.example.tetris.logic.model.Spirit
import com.example.tetris.ui.theme.BrickMatrix
import com.example.tetris.ui.theme.BrickSpirit

@Composable
fun GameScoreboard(
    modifier: Modifier = Modifier,
    brickSize: Float = 35f,
    spirit: Spirit,
    score: Int = 0,
    line: Int = 0,
    level: Int = 1,
    isMute: Boolean = false,
    isPaused: Boolean = false
) {

    Row(modifier.fillMaxSize()) {
        Spacer(modifier = Modifier.weight(0.65f))
        val textSize = 12.sp
        val margin = 12.dp
        Column(modifier = Modifier.weight(0.35f)) {
            Text(text = "Score", fontSize = textSize)
            LedNumber(num = score, digits = 6, modifier = Modifier.fillMaxWidth())

            Spacer(modifier = Modifier.height(margin))

            Text(text = "Lines", fontSize = textSize)
            LedNumber(num = line, digits = 6, modifier = Modifier.fillMaxWidth())

            Spacer(modifier = Modifier.height(margin))

            Text(text = "Level", fontSize = textSize)
            LedNumber(num = level, digits = 1, modifier = Modifier.fillMaxWidth())

            Spacer(modifier = Modifier.height(margin))

            Text(text = "Next", fontSize = textSize)
            Canvas(
                modifier = Modifier
                    .fillMaxWidth()
                    .align(Alignment.CenterHorizontally)
                    .padding(10.dp)
            ) {
                drawMatrix(brickSize, NextMatrix)
                Log.d("cxp", "GameScoreboard: ${spirit.adjustOffset(NextMatrix)}")
                drawSpirit(spirit.adjustOffset(NextMatrix), brickSize, NextMatrix)
            }
            Spacer(modifier = Modifier.weight(1f))

            Row() {
                Image(
                    modifier = Modifier.width(15.dp),
                    imageVector = ImageVector.vectorResource(id = com.example.tetris.R.drawable.ic_baseline_music_off_24),
                    contentDescription = null,
                    colorFilter = ColorFilter.tint(if (isMute) BrickSpirit else BrickMatrix)
                )
                Image(
                    modifier = Modifier.width(15.dp),
                    imageVector = ImageVector.vectorResource(id = com.example.tetris.R.drawable.ic_baseline_pause_24),
                    contentDescription = null,
                    colorFilter = ColorFilter.tint(if (isMute) BrickSpirit else BrickMatrix)
                )
                Spacer(modifier = Modifier.weight(1f))
                LedClock()
            }
        }
    }
}